const t = getApp()
Page({
  data: {
    phone_type:'',
    carnum: [],
    showNewPower: false,
    KeyboardState: false,
    provinces: [
      ['京', '沪', '粤', '津', '冀', '晋', '蒙', '辽', '吉','黑'],
      ['苏', '浙', '皖', '闽', '赣', '鲁', '豫', '鄂','湘'],
      ['桂', '琼', '渝', '川', '贵', '云', '藏'],
      ['陕', '甘', '青', '宁', '新'],
    ],
    numbers: [
      ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
      ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K"],
      ["L", "M", "N", "P", "Q", "R", "S", "T", "U", "V"],
      ["W", "X", "Y", "Z", "港", "澳", "学"]
    ],
    navHeight:t.globalData.navHeight,
    title:'注册',
  },
  onLoad: function (options) {
    var that=this;
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          phone_type:res.platform
        })
      }
    })
  },
  bindChoose(e) {
    if (!this.data.carnum[6] || this.data.showNewPower) {
      var arr = [];
      arr[0] = e.target.dataset.val;
      this.data.carnum = this.data.carnum.concat(arr)
      this.setData({
        carnum: this.data.carnum,
        choose_num:this.data.carnum.length
      })
    }
  },
  bindDelChoose() {
    if (this.data.carnum.length != 0) {
      this.data.carnum.splice(this.data.carnum.length - 1, 1);
      this.setData({
        carnum: this.data.carnum,
        choose_num:this.data.carnum.length
      })
    }
  },
  showPowerBtn() {
    this.setData({
      showNewPower: !this.data.showNewPower,
      KeyboardState: true,
    })
  },
  closeKeyboard() {
    this.setData({
      KeyboardState: false,
      choose_num:null,
    })
  },
  openKeyboard() {
    this.setData({
      KeyboardState: true,
      choose_num:this.data.carnum.length
    })
  },
  choose_car_type(e){
    this.setData({
      showNewPower:true
    })
  },
  formSubmit(e){
    console.log(e.detail.value);
    // if (this.data.showNewPower && this.data.carnum.length!==7) {
    //   wx.showToast({
    //     title: '请输入正确的车牌号',
    //     icon:'none'
    //   })   
    //   return;
    // }
    if(!(/^1[3456789]\d{9}$/.test(e.detail.value.tel))){ 
      wx.showToast({
        title: '请输入正确的手机号',
        icon:'none'
      })   
      return;
    }
    if(!(/^[\u4E00-\u9FA5]{2,4}$/.test(e.detail.value.name))){ 
      wx.showToast({
        title: '请输入正确的姓名',
        icon:'none'
      })   
      return;
    }
  },
  tip(e){
    wx.showToast({
      title: '暂不用填写',
    })
  },
  to_page(e){
    var page 
    switch (e.currentTarget.dataset.page) {
      case 'logon':
        page = '/pages/personCenter/login/logon/logon'
        break;
    
      default:
        break;
    }
    wx.navigateTo({
      url: page,
    })
  }
})